package com.spzx.product.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.spzx.common.core.web.controller.BaseController;
import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.common.core.web.page.TableDataInfo;


import com.spzx.product.domain.Brand;
import com.spzx.product.domain.ProductUnit;
import com.spzx.product.service.BrandService;
import com.spzx.product.service.ProductUnitService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "商品单位接口管理")
@RestController
@RequestMapping("/unit")
public class ProductUnitController extends BaseController {


    @Autowired
    private ProductUnitService productUnitService;


    @Operation(summary = "分页查询商品单位列表")
    @GetMapping("/list")
    public TableDataInfo listProductUnit(ProductUnit productUnit){

       Page<ProductUnit> page  =  productUnitService.selectProductUnitPage(productUnit);
       //调用自己实现的重载方法，把page对象封装为统一响应类
        return getDataTable(page);
    }



    /**
     * 获取商品详细信息
     */
    @Operation(summary = "获取商品单位详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfoProductUnit(@PathVariable("id") Long id)
    {
        ProductUnit productUnit = productUnitService.selectProductUnitById(id);

        return success(productUnit);

    }
/*
    /**
     * 添加内容
     */
    @Operation(summary = "新增商品单位")
    @PostMapping
    public AjaxResult addProductUnit(@RequestBody @Validated ProductUnit productUnit){
        // Brand.setCreateBy(SecurityUtils.getUsername());
        return toAjax(productUnitService.insertProductUnit(productUnit));
    }

    @Operation(summary = "修改商品单位")
    @PutMapping
    public AjaxResult editProductUnit(@RequestBody @Validated ProductUnit productUnit){

        return toAjax(productUnitService.updateProductUnit(productUnit));
    }
    @Operation(summary = "删除商品单位")
    @DeleteMapping("{ids}")
    public AjaxResult removeProductUnit(@PathVariable Long[] ids){
        return toAjax(productUnitService.deleteProductUnitByIds(ids));
    }

    @Operation(summary = "获取全部单位")
    @GetMapping("getUnitAll")
    public AjaxResult selectProductUnitAll() {
        return success(productUnitService.list());
    }
}

